package org.s3.project.controller;

import org.s3.project.entity.ShoppingCart;
import org.s3.project.service.ShoppingCartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * @author cfx
 * @version 1.0
 * @Description
 * @date 2025/2/9 9:34
 */
@CrossOrigin(origins = "*")
@RestController
public class ShoppingCartController {

@Autowired
private ShoppingCartService shoppingCartService;


    //再来一单
    @PostMapping("/addlistShopingCart")
    public String  addlistShopingCart(@RequestBody List<ShoppingCart> shoppingCartList){

        return shoppingCartService.addlistShopingCart(shoppingCartList);
    }


//修改购物车里面的数量
    @PostMapping("updateShoppingCartByid")
    public Boolean updatemerchant(Integer number, Integer user_id, Integer id) {

        return shoppingCartService.updateShoppingCart(number, user_id, id);
    }
    //查询购物车里面是否有这件商品了
    @GetMapping("selectSole")
    int selectSole(Integer user_id , Integer dish_id){

        int s=shoppingCartService.selectSole(user_id,dish_id);
        System.out.println(s+"aaaaa");
        return shoppingCartService.selectSole(user_id, dish_id);
    }

    //新增购物车
    @PostMapping("addShopingCart")
    public Boolean addmerchant(@RequestBody ShoppingCart shoppingCart) {

        return shoppingCartService.save(shoppingCart);
    }
    //添加购物车  有这个商品直接修改他的数量+1
    @PostMapping("updateAddShoping")
    public Boolean  updateAddShoping(Integer user_id,  Integer dish_id) {

    return  shoppingCartService.updateAddShoping(user_id,dish_id);
    }

    // 删除购物车
    @GetMapping("deleteShoping")
    public Boolean deleteShoping( Integer id) {
        return shoppingCartService.removeById(id);
    }

    //批量删除购物车
    @GetMapping("deleteShopings")
    public Boolean deleteShopings(String ids ) {
        String [] split = ids.split(",");
        return  shoppingCartService.deleteShopings(Arrays.asList(split));
    }
}
